package gof.com.yew.flyweight;

import java.util.HashMap;
import java.util.Map;

//创建并管理享元对象，享元池一般设计成键值对
public class FlyWeightFactory {
	
	private static Map<String,ChessFlyWeight> map = new HashMap<>();
	
	public static ChessFlyWeight getFlyWeight(String str) {
		if(map.get(str)!=null) {
			return (ChessFlyWeight)map.get(str);
		}else {
			ChessFlyWeight cfw = new ConcreteChess(str);
			map.put(str, cfw);
			return cfw;
		}
	}

}
